<template>
  <div class="app-container">
    <el-form size="small" label-width="100px" v-formkey="{query:crud.toQuery}">
      <el-row>
        <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
          <el-form-item label="客户">
            <table-select
              :tableColumns="
                  [
                  {prop:'code',label:'供应商编码',width: '100'},
                  {prop:'name',label:'供应商名称',width: '400'},
                  ]"
              labelKey="name"
              valueKey="id"
              width="600"
              :value.sync="query.customerIds"
              placeholder="请选择客户"
              url="api/dropDown/basCustomerList"
            ></table-select>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6"  style="margin-bottom: 5px;margin-top: 5px">
          <rrOperation :crud="crud"/>
        </el-col>
      </el-row>
    </el-form>
    <!--工具栏-->
    <crudOperation :permission="permission" >
      <el-button
        slot="left"
        class="filter-item"
        size="mini"
        type="primary"
        @click="showAdd = true"
      >
        新增
      </el-button>
    </crudOperation>
    <el-dialog  :visible.sync="showAdd" :title="crud.status.title" width="1024px" >
      <customerReturnBillAdd v-if="showAdd" @hide="showAdd = false" @refresh="crud.refresh" />
    </el-dialog>
    <div class="head-container">
      <vue-context-menu :contextMenuData="contextMenuData"
                        @tableConfig="tableConfig"
                        @deletedata="deletedata"></vue-context-menu>
      <!-- 表格配置 -->
      <el-dialog title="表格配置"
                 :visible.sync="tableConfigShow"
                 width="60%">
        <j-table-column-config :columns.sync="crud.header"  @tabSave="tabSave" @pit="pit" />
      </el-dialog>

      <!--表格渲染-->
      <el-table ref="table" border :data="crud.data" size="small"
                style="width: 100%;" v-if="isShowTable"
                @header-dragend="changeColWidth"
                show-summary
                height="700"
                :summary-method="crud.sumRow"
                @row-click="crud.selectRow"
                :row-style="crud.rowClass"
                :row-class-name="crud.tableRowClassName"
                @contextmenu.native="showMenu"
                @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column type="index" width="55" label="序号"/>
        <el-table-column prop="busDate" label="业务日期" />
        <el-table-column prop="closeTime" label="发货时间" />
        <el-table-column prop="code" label="回单编码" />
        <el-table-column prop="customerName" label="客户名称" />
        <el-table-column prop="slipDate" label="回单日期" />
        <el-table-column prop="slipTaxAmount" label="回单金额" />
        <el-table-column prop="sourceCode" label="来源单据号" />
      </el-table>
      <!--分页组件-->

      <pagination/>
    </div>
  </div>
</template>

<script>
import crudReportDriverLoad from '@/api/erp/customerReturnBill'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import {getBasGoodsTypeTree} from "@/api/erp/basGoodsType";
import Treeselect from '@riophae/vue-treeselect'
import {get} from '@/api/erp/reportDriverLoad'
import { publicListKey } from "@/utils/key";
import {getHeaderProperties} from "@/api/erp/headerProperties";
import {tablemixins} from "@/mixins/tablemixins";
import  jTableColumnConfig  from "@/components/jTableColumnConfig/jTableColumnConfig";
import {getAreaTree} from "@/api/erp/basCustomerArea";
import {getCustomerTypeTree} from "@/api/erp/basCustomerType";
import tableSelect from '@/components/tableSelect/tableSelect'
import jtgSelectPlus from "@/components/select/JtgSelectPlus.vue";
import CustomerReturnBillAdd from "@/views/erp/customerReturnBill/customerReturnBilladd.vue";


// crud交由presenter持有
const defaultCrud = CRUD({ title: '客户回单',
  optShow: {
    add: false,
    edit: false,
    del: true,
    download: false,
    leadingIn: false,
    enable: false,
    disable: false,
    pass: false,
    reject: false,
    invalid: false,
    recover: false,
    downloadDetail: false,
    print: false,
    printDetail: false
  },
  url: 'api/customerSlip', sort: '',
  crudMethod: { ...crudReportDriverLoad }})
const defaultForm = { busDate: null, orderType: null, orderId: null, orderCode: null, orderName: null, orderStatus: null, customerId: null, customerCode: null, customerName: null, pCustomerId: null, pCustomerCode: null, pCustomerName: null, mCustomerId: null, mCustomerCode: null, mCustomerName: null, deptId: null, deptCode: null, deptName: null, userId: null, userCode: null, userName: null, warehouseId: null, warehouseCode: null, warehouseName: null, orderRemark: null, goodsId: null, goodsCode: null, goodsName: null, packageType: null, barcode: null, boxBarcode: null, helpSign: null, model: null, goodsBrandId: null, goodsBrandCode: null, goodsBrandName: null, goodsTypeId: null, goodsTypeCode: null, goodsTypeName: null, goodsTagId: null, goodsTagCode: null, goodsTagName: null, boxUnitId: null, boxUnitCode: null, boxUnitName: null, boxUnitCount: null, boxNum: null, mainUnitId: null, mainUnitCode: null, mainUnitName: null, mainUnitCount: null, mainNum: null, goodsCount: null, boxCount: null, taxPrice: null, noTaxPrice: null, taxBoxPrice: null, noTaxBoxPrice: null, taxAmount: null, noTaxAmount: null, tax: null, acceptGoodsCount: null, acceptBoxCount: null, acceptBoxNum: null, acceptMainNum: null, acceptTaxAmount: null, acceptNoTaxAmount: null, acceptTax: null, cancelAmount: null, unCancelAmount: null, goodsRemark: null, createUserId: null, createUserCode: null, createUserName: null, createTime: null, auditUserId: null, auditUserCode: null, auditUserName: null, auditTime: null, closeUserId: null, closeUserCode: null, closeUserName: null, closeTime: null, acceptDate: null, acceptUserId: null, acceptUserCode: null, acceptUserName: null, cancelDate: null, cancelUserId: null, cancelUserCode: null, cancelUserName: null, id: null }
export default {
  name: 'customerReturnBill',
  components: {
    CustomerReturnBillAdd,
    jtgSelectPlus, pagination, crudOperation, rrOperation, udOperation,Treeselect,jTableColumnConfig, tableSelect },
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud(),publicListKey,tablemixins],
  dicts:['t_report_Driver_flow_order_type','common_order_status','common_cancel_status','common_yes_or_no','t_bas_goods_package_type'],
  mounted(){

  },
  created() {

  },
  data() {
    return {
      customerTypeIds:[],
      isSend:[],
      showAdd:false,
      fCustomerIds:[],
      pCustomerIds:[],
      mCustomerIds:[],
      customerAreaIds:[],
      total:0,
      areaList:[],
      orderType:[],
      cancelStatus:[],
      orderStatus:[],
      createdataExtent:[],
      dialogVisible:false,
      dataExtent:[],
      dataExtent01:[],
      dataExtent02:[],
      goodsTypeIds:[],
      goodsBrandIds:[],
      warehouseIds:[],
      goodsIds:[],
      driverUserIds:[],
      areaData:[],
      customerIds:[],
      sCustomerIds:[],
      packageType:[],
      defaultProps: {
        children: 'children',
        label: 'name'
      },
      jumpPath:[
        '/sale/salesorderDetail/',
        '/sale/salesorderDetail/',
        '/ware/wareReturnBottleBoxDetail/',
      ],
      goodsTagList:[],
      userIds:[],
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit('pick', [start, end]);
          }
        }]
      },

      permission: {
        add: ['admin', 'reportDriverLoad:add'],
        edit: ['admin', 'reportDriverLoad:edit'],
        del: ['admin', 'reportDriverLoad:del'],
        import: ['admin', 'reportDriverLoad:import'],
        export: ['admin', 'reportDriverLoad:export'],
        copy: ['admin', 'reportDriverLoad:copy'],
        upload: ['admin', 'reportDriverLoad:upload'],
        download: ['admin', 'reportDriverLoad:download'],
        pass: ['admin', 'reportDriverLoad:pass'],
        reject: ['admin', 'reportDriverLoad:reject'],
        closed: ['admin', 'reportDriverLoad:closed'],
        invalid: ['admin', 'reportDriverLoad:invalid'],
        stop: ['admin', 'reportDriverLoad:stop'],
        recover: ['admin', 'reportDriverLoad:recover'],

      },
      rules: {
        goodsId: [
          { required: true, message: '商品id不能为空', trigger: 'blur' }
        ]
      },
    }
  },
  updated() {
    this.$nextTick(() => {
      this.$refs.table.doLayout()
    })
  },
  watch: {

  },
  methods: {
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }, // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form) {
    },

    normalizer(node) {
      //去掉children=[]的children属性
      if (node.children == null || node.children.length == 0) {
        delete node.children;
      }
      return {
        id: node.id,
        label: node.name,
        children: node.children
      }
    },
    init(){
      this.page = 1
    },

    onGet(){
      const that =this
      let { page,size } = this.crud.page
      page =  1
      get({...this.query,page,size}).then(res=>{
        that.crud.data = res.data.content
        that.crud.page.total = res.data.totalElements
        console.log(that.total)
      })
    },
  }
}
</script>

<style lang="scss" scoped>
.table-img {
  display: inline-block;
  text-align: center;
  background: #ccc;
  color: #fff;
  white-space: nowrap;
  position: relative;
  overflow: hidden;
  vertical-align: middle;
  width: 32px;
  height: 32px;
  line-height: 32px;
}
.flex{
  display: flex;
}
.fow-reverse{
  flex-direction: row-reverse;
}
.codeJump{
  background-image:-webkit-linear-gradient(top,yellow,#ff00fb);
  -webkit-background-clip:text;
  -webkit-text-fill-color:transparent;
  cursor: pointer;
}
</style>
